<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class dbase extends CI_Model {
    
	function __construct() 
	{
		parent::__construct();
	}
        
        function userinfo($steamid)
        {
            $this->db->select(array('id','steamid', 'nickname', 'avatar'))->from('users')->where('steamid', $steamid);
            $query = $this->db->get();
            return $query;
            
            /*$result = array();
            foreach($query->result() as $row)
            {
                $result['steamid'] = $row->steamid;
                        
            }*/
            
            return $query;
        }
        
        function userupdate($data)
        {
            $this->db->insert('users', $data);
        }
        
        function get_News($page)
        {   
            $news_per_page = 10;
            $this->db->select(array('id', 'title', 'text', 'date'))->from('news')->limit($news_per_page, $news_per_page*($page-1))->order_by('date', 'desc');
            $news = $this->db->get();
            return $news->result_array();
        }
        
        function post_News($title, $text)
        {
            $data = array(
                'title' => $title,
                'text' => $text,
            );
            $this->db->insert('news', $data);
        }
        
        function check_admin()
        {
            $this->db->select(array('steamid','admin'))->from('users')->where('steamid', $this->session->userdata('steamid'));
            $query = $this->db->get();
            print_r($query->result_array());
            return $query->result_array('admin');
        }
        
        function update_admin($steamid, $level)
        {
            $this->db->where('steamid', $steamid);
            $this->db->update('users', array('admin', $level));
        }
        
        function team_admin_check($teamid, $playerid)
        {
            $this->db->select(array('playerid', 'team1', 'team2', 'team3'))->from('team_players');
            $this->db->where(array('playerid' => $playerid, 'team1' => $teamid));
            $this->db->or_where(array('playerid' => $playerid, 'team2' => $teamid));
            $this->db->or_where(array('playerid' => $playerid, 'team3' => $teamid));
            $result = $this->db->get();
            if ($result->num_rows() > 0)
            {
                return TRUE;
            } else {
                return FALSE;
            }
        }
        
        function team_info($teamid)
        {
            $this->db->select()->from(array('team_players', 'teams'));
        }
        
        function create_team($title, $description, $avatar)
        {
            $data = array(
                'title' => $title,
                'description' => $description,
                'avatar' => $avatar,
                'game' => 'dota',
            );
            
            $this->db->insert('teams', $data);           
        }
        
}


/* End of file database.php */
/* Location: ./application/models/database.php */
